package com.teewe.model.data
{
	import com.teewe.utils.*;
	
	public class DataTypeBase implements IDisposable
	{
		public function DataTypeBase(xml:XML)
		{
			parse (xml);
		}
		
		protected function parse (xml:XML):void
		{
			if (xml == null)
				return;
				
			var children:XMLList = xml.children();
			var child:XML, attName:String, attValue:*;
			
			for each (child in children)
			{
				attName = child.name();
				attValue = ClassUtils.xmlToType(child);
				
				this[attName] = attValue;
			}
		}
		
		public function dispose ():void
		{
			var propertyList:Array = ClassUtils.getPropertyList (this);
			var propertyName:String, property:*;
				
			for each (propertyName in propertyList)
			{
				property = this[propertyName];
				if (ClassUtils.isPrimitive (property) == false)
				{
					if (property is IDisposable)
						property.dispose ();
					
					this[propertyName] = null;
				}
			}
		}
	}
}